// pages/shop/order/list/list.js
import tips from '../../../../class/Utils/Tips'
import http from '../../../../service/http.js'

var loadMore = function (that) {

  var page = that.data.page;
  var page_size = '10';
  var user = wx.getStorageSync('user');
  var userid = user.userid;
  var type = that.data.type
  var url = '/Wxorder/order_list';
  console.log(url)
  http.req(url, {type:type,userid:userid,page:page,page_size:page_size}, function (res) {

    if (res.data) {
      var prolist = that.data.prolist;
      for (var i = 0; i < res.data.length; i++) {
        prolist.push(res.data[i]);
      }
      that.setData({
        lock: 1,
        prolist: prolist
      });
      page = parseInt(page) + parseInt(page_size);
      wx.hideLoading()
      console.log(prolist)
    } else {
      wx.hideLoading()
      if (page == '0') {
        if (res.code == '202') {
          that.setData({
            nolist: 1
          })
          wx.showToast({
            title: '无记录',
            icon: 'success',
            duration: 2000
          })
        }
      } else {
        if (res.code == '202') {
          wx.showToast({
            title: '加载完毕',
            icon: 'success',
            duration: 2000
          })
        }
      }

      if (page == '0') {
        that.setData({
          s: 2
        });
      }
    }
    that.setData({
      page: page
    });
  });

}
Page({

  data: {
    currentTab:0,
    prolist:[],
    page: 0,
    lock: 1,
    jiazai: 1,
    s: 1,
    type: 11
  },
  //切换导航
  swichNav:function(e){
    var that = this;
    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current
      })
    }
    var type = e.currentTarget.dataset.type
    that.setData({
      page: 0,
      s: 1,
      prolist: [],
      lock: 1,
      type: type,
      dianji: 1

    })
    loadMore(that)
  },
  onLoad: function (get) {
    var that = this
    
    var type = get.type
    if (type) {
      that.setData({
        type: type,
        currentTab: type
      })
    }
  },
  onShow: function () {
    //获取页面高度
    //获取高度宽度等
    var that = this;
    wx.getSystemInfo({
      success: function (res) {
        var pageWidth = res.windowWidth - 20;
        var pjvieww = pageWidth * 0.2
        that.setData({
          scrollHeight: res.windowHeight,
          pjuserpicliH: pjvieww
        });
      }
    });
    that.setData({
      prolist: [],
      page: 0,
      lock: 1,
      jiazai: 1,
      s: 1,
    })
    loadMore(that, that.data.type)

  },
  /*
  确认收货
   */
  queren: function (e) {
    var that = this
    var prolist = that.data.prolist
    var id = e.currentTarget.dataset.id
    var index = e.currentTarget.dataset.index
    wx.showModal({
      title: '温馨提示',
      content: '是否确认收货',
      cancelText: "再想想",
      confirmText: "确认收货",
      success: function (res) {
        if (res.confirm) {

          http.req('/Wxorder/shouhuo', {id:id}, function (res) {

            if (res.code == '1') {
              prolist[index].status = '3'
              that.setData({
                prolist: prolist
              })
              wx.showToast({
                title: '操作成功',
                icon: 'success',
                duration: 2000
              })

              that.setData({
                page: 0,
                s: 1,
                prolist: [],
                lock: 1,
                type: 3,
                dianji: 1,
                currentTab: 3
              })
              loadMore(that)
            } else {
              wx.showToast({
                title: '参数错误',
                icon: 'success',
                duration: 2000
              })
            }

          });
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  gotolink:function(e){
    var that = this
    var thisurl = e.currentTarget.dataset.url
    tips.goto(thisurl)
  }

  
})